package com.edushare.common.dao;

import java.util.HashMap;
import java.util.List;

import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.query.SelectQuery;

import com.edushare.common.orm.ORMInterface;
import com.edushare.common.vo.AssignmentFiles;
import com.edushare.common.vo.Assignments;
import com.edushare.common.vo.Users;

public class AssignmentFilesDAO extends CayenneBasedDAO {

	public AssignmentFilesDAO(ORMInterface ormInterface) {
		super(ormInterface);
	}
	
	@SuppressWarnings("unchecked")
	public List<AssignmentFiles> getAssignmentFilesForUser
			(Users u, Assignments a, int assignmentFileVisibility)
	{
		Expression exp = Expression.fromString("uploader = $usr " +
												"and assignment = $asgn " +
												"and visibility = $visible");
		HashMap hm = new HashMap();
		hm.put("usr", u);
		hm.put("asgn", a);
		hm.put("visible", new Integer(assignmentFileVisibility));
		SelectQuery query = new SelectQuery(AssignmentFiles.class, exp.expWithParameters(hm));
		return (List<AssignmentFiles>)getDataContext().performQuery(query);
	}

	public void create(AssignmentFiles af) {
		getDataContext().registerNewObject(af);
		getDataContext().commitChanges();
	}

}
